define([
    './ToolBar',
    '../../ThirdParty/navigation',
    './PositionElement'
], function(
    ToolBar, 
    viewerCesiumNavigationMixin,
    PositionElement
) {
    'use strict';
    var viewer, toolBar, positionElement, position;
    /**
     * 初始化函数
     */
    function init(){
        viewer =  new Cesium.Viewer('cesiumContainer',{
            animation : false,
            // timeline : false,
            geocoder : false,
            baseLayerPicker : false,
            fullscreenButton : false,
            vrButton : false,
            homeButton : false,
            //infoBox : false,
            sceneModePicker : false,
            //selectionIndicator : false,
            navigationHelpButton : false
        });
        viewer._cesiumWidget._creditContainer.style.display = 'none';
        // 创建地形
        var terrainProvider = Cesium.createWorldTerrain({
            //url : 'https://assets.agi.com/stk-terrain/world',
            requestVertexNormals : true,    // 指示客户端是否应从服务器请求其他照明信息
            requestWaterMask : true         // 指示客户端是否应从服务器请求每个瓦片水掩模
        });

        // 添加地形
        //viewer.terrainProvider = terrainProvider;
        // 开启地形深度测试
        //viewer.scene.globe.depthTestAgainstTerrain = true;
        // 开启地形照明效果
        viewer.scene.globe.enableLighting = true;
        // 显示帧率
        viewer.scene.debugShowFramesPerSecond = true;
        //显示指南针
        viewer.extend(Cesium.viewerCesiumNavigationMixin, {});
        viewer.trackedEntity = undefined;
        // 禁用双击选中实体
        viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
            Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
        );
        // 创建工具栏
        toolBar = new ToolBar('controller');
        // 创建位置显示元素
        positionElement = new PositionElement(viewer, document.getElementById('cesiumContainer'));
        position = positionElement.position;
        // 调试模式
        viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
        var inspectorViewModel = viewer.cesium3DTilesInspector.viewModel;

    }
    if( typeof viewer === 'undefined' || typeof toolBar === 'undefined' || typeof positionElement === 'undefined'){
        init();
    }
    return {
        viewer, 
        toolBar,
        position
    };
});